package com.mju.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.mju.dao.UsersMapper;
import com.mju.model.dto.SecurityUser;
import com.mju.model.dto.UserInfo;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

	@Autowired
	private UsersMapper usersMapper;
	
	@Override
	public UserDetails loadUserByUsername(String username) 
				throws UsernameNotFoundException {
		
		//Users u=usersMapper.selectByPrimaryKey(username);
		UserInfo u=usersMapper.getUserInfo(username);
		if(u==null) throw new UsernameNotFoundException("用户或密码错误！");
				
		SecurityUser user=new SecurityUser(u);

		return user;
	}
}
